package com.gagakuai.demo.compoentFiter;

import com.gagakuai.demo.service.OrderService;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-12 11:16
 */
public class MyCompoentFilter implements TypeFilter {


    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        Class<?> aClass = null;
        //当前被扫描到的类
        String className = metadataReader.getClassMetadata().getClassName();
        try {
            aClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
        }
        boolean assignableFrom = OrderService.class.isAssignableFrom(aClass);

        return assignableFrom;
    }
}